package com.itheiya.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 定义配置类  声明交换机, 队列 , 队列与交换价进行绑定
 */
@Configuration
public class MqConfig {
    /**
     * 声明交换机
     */
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("item.topic");
    }

    /**
     * 声明insert 队列
     */
    @Bean
    public Queue insertQueue() {
        return new Queue("item.insert.queue");
    }


    /**
     * 声明delete 队列
     */
    @Bean
    public Queue deleteQueue() {
        return new Queue("item.delete.queue");
    }

    /**
     * insert 队列与交换机绑定
     * @return
     */
    @Bean
    public Binding binding1(){
        return BindingBuilder.bind(insertQueue()).to(topicExchange()).with("item.insert");
    }

    /**
     * insert 队列与交换机绑定
     * @return
     */
    @Bean
    public Binding binding2(){
        return BindingBuilder.bind(deleteQueue()).to(topicExchange()).with("item.delete");
    }
}
 